package com.diploma.project.aiqiyi.utils;

import java.util.Date;
import java.util.List;
import java.util.Map;

public class WechatMsgTplUtil {

    /**
     * 回复文本信息
     *
     * @param ToUserName
     * @param FromUserName
     * @param Content
     * @return
     */
    public static String replyText(String ToUserName, String FromUserName, String Content) {

        String textMsgTmpl = "<xml>" +
                "<ToUserName><![CDATA[" + ToUserName + "]]></ToUserName>" +
                "<FromUserName><![CDATA[" + FromUserName + "]]></FromUserName> " +
                "<CreateTime>" + new Date().getTime() + "</CreateTime>" +
                "<MsgType><![CDATA[text]]></MsgType>" +
                "<Content><![CDATA[" + Content + "]]></Content>" +
                "</xml>";
        return textMsgTmpl;
    }

    /**
     * 转发客服信息(kfaccount为空串)
     *
     * @param ToUserName
     * @param FromUserName
     * @param msgType
     * @return
     */
    public static String textTp(String ToUserName, String FromUserName, String msgType) {

        String texttp = "<xml>\n" +
                "<ToUserName><![CDATA[" + ToUserName + "]]></ToUserName>\n" +
                "<FromUserName><![CDATA[" + FromUserName + "]]></FromUserName> \n" +
                "<CreateTime>" + new Date().getTime() + "</CreateTime>\n" +
                "<MsgType><![CDATA[" + "transfer_customer_service" + "]]></MsgType>\n" +
                "</xml>";
        return texttp;
    }

    /**
     * 回复文本信息(kfaccount不为空串)
     *
     * @param ToUserName
     * @param FromUserName
     * @param kfaccount
     * @param msgType
     * @return
     */
    public static String textTps(String ToUserName, String FromUserName, String kfaccount, String msgType) {

        String texttps = "<xml>\n" +
                "<ToUserName><![CDATA[" + ToUserName + "]]></ToUserName>\n" +
                "<FromUserName><![CDATA[" + FromUserName + "]]></FromUserName> \n" +
                "<CreateTime>" + new Date().getTime() + "</CreateTime>\n" +
                "<MsgType><![CDATA[" + "transfer_customer_service" + "]]></MsgType>\n" +
                "<TransInfo>\n<KfAccount><![CDATA[" + kfaccount + "]]></KfAccount>\n</TransInfo>\n" +
                "</xml>";
        return texttps;
    }

    /**
     * 要回复的消息信息
     *
     * @param newsList
     * @return
     */
    public static String newsMsgInnerTmpl(Map<String, String> newsList) {
        String newsMsg = "<item>\n" +
                "<Title><![CDATA[" + newsList.get("title") + "]]></Title>\n" +
                "<Description><![CDATA[" + newsList.get("description") + "]]></Description>\n" +
                "<PicUrl><![CDATA[" + newsList.get("picurl") + "]]></PicUrl>\n" +
                "<Url><![CDATA[" + newsList.get("url") + "]]></Url>\n" +
                "</item>\n";
        return newsMsg;
    }

    /**
     * 回复消息信息
     *
     * @param ToUserName
     * @param FromUserName
     * @param newsList
     * @param innerstr
     * @return
     */
    public static String replyNewsMsg(String ToUserName, String FromUserName, List<Map<String, String>> newsList, String innerstr) {
        String replyNews = "<xml>\n" +
                "<ToUserName><![CDATA[" + ToUserName + "]]></ToUserName>\n" +
                "<FromUserName><![CDATA[" + FromUserName + "]]></FromUserName>\n" +
                "<CreateTime>" + new Date().getTime() + "</CreateTime>\n" +
                "<MsgType><![CDATA[news]]></MsgType>\n" +
                "<ArticleCount>" + newsList.size() + "</ArticleCount>\n" +
                "<Articles>\n" +
                innerstr + "\n" +
                "</Articles>\n" +
                "</xml>";
        return replyNews;
    }

    /**
     * 回复图片信息
     *
     * @param ToUserName
     * @param FromUserName
     * @param mediaId
     * @return
     */
    public static String replyImageMsg(String ToUserName, String FromUserName, String mediaId) {
        String imageMsgTmpl = "<xml>\n" +
                "<ToUserName><![CDATA[" + ToUserName + "]]></ToUserName>\n" +
                "<FromUserName><![CDATA[" + FromUserName + "]]></FromUserName>\n" +
                "<CreateTime>" + new Date().getTime() + "</CreateTime>\n" +
                "<MsgType><![CDATA[image]]></MsgType>\n" +
                "<Image>\n" +
                "<MediaId><![CDATA[" + mediaId + "]]></MediaId>\n" +
                "</Image>\n" +
                "</xml>";
        return imageMsgTmpl;
    }

    /**
     * 回复视频信息
     *
     * @param ToUserName
     * @param FromUserName
     * @param mediaId
     * @return
     */
    public static String replyVoiceMsg(String ToUserName, String FromUserName, String mediaId) {
        String voiceMsgTmpl = "<xml>\n" +
                "<ToUserName><![CDATA[" + ToUserName + "]]></ToUserName>\n" +
                "<FromUserName><![CDATA[" + FromUserName + "]]></FromUserName>\n" +
                "<CreateTime>" + new Date().getTime() + "</CreateTime>\n" +
                "<MsgType><![CDATA[voice]]></MsgType>\n" +
                "<Voice>\n" +
                "<MediaId><![CDATA[" + mediaId + "]]></MediaId>\n" +
                "</Voice>\n" +
                "</xml>";
        return voiceMsgTmpl;
    }

    /**
     * 回复视频信息(with title,desc)
     *
     * @param ToUserName
     * @param FromUserName
     * @param mediaId
     * @param title
     * @param desc
     * @return
     */
    public static String replyVoiceMsg(String ToUserName, String FromUserName, String mediaId, String title, String desc) {
        String voiceMsgTmpl = "<xml>\n" +
                "<ToUserName><![CDATA[" + ToUserName + "]]></ToUserName>\n" +
                "<FromUserName><![CDATA[" + FromUserName + "]]></FromUserName>\n" +
                "<CreateTime>" + new Date().getTime() + "</CreateTime>\n" +
                "<MsgType><![CDATA[video]]></MsgType>\n" +
                "<Video>\n" +
                "<MediaId><![CDATA[" + mediaId + "]]></MediaId>\n" +
                "<Title><![CDATA[" + title + "]]></Title>\n" +
                "<Description><![CDATA[" + desc + "]]></Description>\n" +
                "</Video>\n" +
                "</xml>";
        return voiceMsgTmpl;
    }

    /**
     * 回复音乐信息
     *
     * @param ToUserName
     * @param FromUserName
     * @param title
     * @param desc
     * @param musicurl
     * @param hqmusicurl
     * @param thumbmediaid
     * @return
     */
    public static String replyMusicMsg(String ToUserName, String FromUserName, String title, String desc, String musicurl, String hqmusicurl, String thumbmediaid) {
        String musicMsgTmpl = "<xml>\n" +
                "<ToUserName><![CDATA[" + ToUserName + "]]></ToUserName>\n" +
                "<FromUserName><![CDATA[" + FromUserName + "]]></FromUserName>\n" +
                "<CreateTime>" + new Date().getTime() + "</CreateTime>\n" +
                "<MsgType><![CDATA[music]]></MsgType>\n" +
                "<Music>\n" +
                "<Title><![CDATA[" + title + "]]></Title>\n" +
                "<Description><![CDATA[" + desc + "]]></Description>\n" +
                "<MusicUrl><![CDATA[" + musicurl + "]]></MusicUrl>\n" +
                "<HQMusicUrl><![CDATA[" + hqmusicurl + "]]></HQMusicUrl>\n" +
                "<ThumbMediaId><![CDATA[" + thumbmediaid + "]]></ThumbMediaId>\n" +
                "</Music>\n" +
                "</xml>";
        return musicMsgTmpl;
    }

    /**
     * 获取电子签约提醒模版（微众）-调起小程序
     * @param toUser
     * @param templateId
     * @param title
     * @param keyword1
     * @param keyword2
     * @param remark
     * @param miniProgramAppid
     * @param miniProgramPagePath
     * @return
     */
    public static String getSignRemindTplByMiniProgram(String toUser,
                                                       String templateId,
                                                       String title,
                                                       String keyword1,
                                                       String keyword2,
                                                       String remark,
                                                       String miniProgramAppid,
                                                       String miniProgramPagePath) {
        String msgTemplate = "{" +
                            "\"touser\":\"%s\","          +
                            "\"template_id\":\"%s\","     +
                            "\"topcolor\":\"#FF0000\","   +
                            "\"data\":"                   +
                            "{"                           +
                            "\"first\": {"                +
                            "\"value\":\"%s\","           +
                            "\"color\":\"#000000\""       +
                            "},"                          +
                            "\"keyword1\": {"             +
                            "\"value\":\"%s\","           +
                            "\"color\":\"#0000FF\""       +
                            "},"                          +
                            "\"keyword2\":{"              +
                            "\"value\":\"%s\","           +
                            "\"color\":\"#0000FF\""       +
                            "},"                          +
                            "\"remark\": {"               +
                            "\"value\":\"%s\","           +
                            "\"color\":\"#000000\""       +
                            "}"                           +
                            "},"                          +
                            "\"miniprogram\":{"           +
                            "\"appid\":\"%s\","           +
                            "\"pagepath\":\"%s\"}"        +
                            "}";
        return String.format(msgTemplate, toUser, templateId, title, keyword1,
                keyword2, remark, miniProgramAppid, miniProgramPagePath);
    }

    /**
     * 获取电子签约提醒模版（会分期）-url
     * @param toUser
     * @param templateId
     * @param title
     * @param keyword1
     * @param keyword2
     * @param remark
     * @param jumpUrl
     * @return
     */
    public static String getSignRemindTplByUrl(String toUser,
                                               String templateId,
                                               String title,
                                               String keyword1,
                                               String keyword2,
                                               String remark,
                                               String jumpUrl) {
        String msgTemplate = "{" +
                            "\"touser\":\"%s\","          +
                            "\"template_id\":\"%s\","     +
                            "\"url\":\"%s\","             +
                            "\"topcolor\":\"#FF0000\","   +
                            "\"data\":"                   +
                            "{"                           +
                            "\"first\": {"                +
                            "\"value\":\"%s\","           +
                            "\"color\":\"#000000\""       +
                            "},"                          +
                            "\"keyword1\": {"             +
                            "\"value\":\"%s\","           +
                            "\"color\":\"#0000FF\""       +
                            "},"                          +
                            "\"keyword2\":{"              +
                            "\"value\":\"%s\","           +
                            "\"color\":\"#0000FF\""       +
                            "},"                          +
                            "\"remark\": {"               +
                            "\"value\":\"%s\","           +
                            "\"color\":\"#000000\""       +
                            "}"                           +
                            "}}";
        return String.format(msgTemplate, toUser, templateId, jumpUrl, title, keyword1, keyword2, remark);
    }

    /**
     * 获取待付款提醒模版-通过url跳转
     * @param toUser
     * @param templateId
     * @param title
     * @param keyword1
     * @param keyword2
     * @param keyword3
     * @param remark
     * @param jumpUrl
     * @return
     */
    public static String getNonPaymentTplByUrl(String toUser,
                                               String templateId,
                                               String title,
                                               String keyword1,
                                               String keyword2,
                                               String keyword3,
                                               String remark,
                                               String jumpUrl) {
        String msgTemplate = "{"                          +
                            "\"touser\":\"%s\","          +
                            "\"template_id\":\"%s\","     +
                            "\"url\":\"%s\","             +
                            "\"topcolor\":\"#FF0000\","   +
                            "\"data\":{"                  +
                            "\"first\": {"                +
                            "\"value\":\"%s\","           +
                            "\"color\":\"#000000\""       +
                            "},"                          +
                            "\"keyword1\": {"             +
                            "\"value\":\"%s\","           +
                            "\"color\":\"#0000FF\""       +
                            "},"                          +
                            "\"keyword2\":{"              +
                            "\"value\":\"%s\","           +
                            "\"color\":\"#0000FF\""       +
                            "},"                          +
                            "\"keyword3\":{"              +
                            "\"value\":\"%s\","           +
                            "\"color\":\"#0000FF\""       +
                            "},"                          +
                            "\"remark\": {"               +
                            "\"value\":\"%s\","           +
                            "\"color\":\"#000000\""       +
                            "}"                           +
                            "}}";
        return String.format(msgTemplate, toUser, templateId, jumpUrl, title, keyword1,
                keyword2, keyword3, remark);
    }

    /**
     * 获取订单支付成功提醒模版-无跳转
     * @param toUser
     * @param templateId
     * @param title
     * @param orderMoneySum
     * @param orderProductName
     * @return
     */
    public static String getPaymentSuccessTpl(String toUser,
                                               String templateId,
                                               String title,
                                               String orderMoneySum,
                                               String orderProductName) {
        String msgTemplate = "{"                          +
                            "\"touser\":\"%s\","          +
                            "\"template_id\":\"%s\","     +
                            "\"topcolor\":\"#FF0000\","   +
                            "\"data\":{"                  +
                            "\"first\": {"                +
                            "\"value\":\"%s\","           +
                            "\"color\":\"#000000\""       +
                            "},"                          +
                            "\"orderMoneySum\": {"             +
                            "\"value\":\"%s\","           +
                            "\"color\":\"#0000FF\""       +
                            "},"                          +
                            "\"orderProductName\":{"              +
                            "\"value\":\"%s\","           +
                            "\"color\":\"#0000FF\""       +
                            "}"                          +
                            "}}";
        return String.format(msgTemplate, toUser, templateId, title, orderMoneySum, orderProductName);
    }
}
